package com.example.ywj.http.OKHttps;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.ywj.http.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class GetSyncActivity extends AppCompatActivity {
    private static final String TAG = "GetSyncActivity";
    @BindView(R.id.bottom_sync_get)
    public Button btn_sync_get;
    @BindView(R.id.sync_username)
    public EditText et_sync_username;
    @BindView(R.id.sync_password)
    public EditText et_sync_password;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_get_sync);
        ButterKnife.bind(this);
    }
    @OnClick({R.id.bottom_sync_get})
    public void onClickView(View view){
        switch (view.getId()){
            case R.id.bottom_sync_get:
                //Toast.makeText(GetSyncActivity.this,"123",Toast.LENGTH_LONG).show();
                func();
                break;
        }
    }
    public void func(){
        new Thread(){
            @Override
            public void run() {
                //super.run();
                String path = "http://10.15.180.121:3009/addUser?username="+et_sync_username.getText().toString().trim()+"&password="+et_sync_password.getText().toString().trim();
                //创建对象
                OkHttpClient client = new OkHttpClient();
                //创建request对象
                Request request = new Request.Builder().get()
                        .url(path)
                        .build();
                //创建call对象
                Call call = client.newCall(request);
                try{
                    Response response = call.execute();
                    if(response.isSuccessful()){
                        String res = response.body().string();
                        Log.i(TAG, "run: "+res);
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }.start();
    }
}
